<?php
define("INWEB",true);
include('include/config.php');
if($_POST || $_GET)
{
    if(isset($_GET['updmd5']) && getConfig('settings', 'md5enc','0')=='0')
    {
        $qry=$sql->query("SELECT id, pass FROM `employees`");
        while($usr=$sql->fetch_array($qry))
        {
            $pass=$user->encpass($usr['pass']);
            $sql->query("UPDATE `employees` SET pass='$pass' WHERE id='{$usr['id']}'");
        }
        setConfig('settings','md5enc','1');
        suc('Success','Passwords encrypted');
        
    }
    if(!isset($_POST['login']) && !isset($_POST['pass']))
    {
        err('Error','Missing data');
    }
    if($user->checkLogin($_POST['login'],$_POST['pass'],isset($_POST['remember'])?$_POST['remember']:0))
    {
        if(isset($_SESSION['returnto']))
            header ("Refresh: 0; url={$_SESSION['returnto']}");
        else
            header ("Refresh: 0; url=index.php");
    }else{
        header ("Refresh: 3; url=login.php");
        err("Error", "You have failed to log in");
    }
}
else
{
    $user->logout();
    head('Login',0);
    ?>
    <div id="login-logo"><img src="img/inko.png" alt="inko" width="320" height="182" /></div>
    <div id="login-gradient">&nbsp;</div>
  <div id="login-box">
    <form method="post" action="">
      <fieldset class="textbox">
        <div>
        <span class="holder">Username</span>
          <input type="text" title="Username" name="login" value="" />
        </div>
        <div>
        <span class="holder">Password</span>
          <input type="password" title="Password" name="pass" />
        </div>
      </fieldset>
      <fieldset class="subchck">
        <label class="remember">
          <input type="checkbox" name="remember" />
          <span>Remember me</span>
        </label>
        <button class="yt_button" type="submit">Sign in</button>
      </fieldset>
<input type="hidden" value="" name="returnto" />
                                                             
    </form>
  </div>
    <?php
    foot(0);
}
?>